package com.jy.wms.controller;

import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsGoodsBom;
import com.jy.wms.service.WmsGoodsBomService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import java.util.Map;

import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsGoodsBomController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Wed Dec 27 17:07:41 CST 2017
 */
@Controller
@RequestMapping("/wmsgoodsbom")
@Api(value = "/wmsgoodsbom", description = "货品物料清单")
public class  WmsGoodsBomController extends BaseController<WmsGoodsBomService,WmsGoodsBom> {

    @PostMapping(value = "list")
    @ApiOperation(value = "查询信息",response = JSONObject.class, notes = "查询信息")
    public @ResponseBody ResultPage<WmsGoodsBom> getWmsGoodsBom(@RequestBody WmsGoodsBom entity,HttpSession session) {
        Page<WmsGoodsBom> list= baseService.baseSelectPage(entity);
            return renderPage(list);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除信息",response = JSONObject.class, notes = "删除信息")
    public @ResponseBody JsonResult deleteWmsGoodsBom(@RequestBody List<String> ids) {
        Integer flag=baseService.baseDeleteBathPrimaryKeys(ids);
        return renderSuccess("删除成功");
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增货品物料清单信息",response = JSONObject.class, notes = "新增货品物料清单信息")
    public @ResponseBody JSONObject addWmsGoodsBom(@RequestBody Map<String,Object> map) {
        try{
            baseService.baseInsert(map);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"新增货品物料清单信息成功","", JSONArray.fromObject(map).toString());
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"新增货品物料清单信息失败",e.getMessage(),"");
        }

    }

    @PostMapping(value = "getWmsGoodsBom/{sshpid}")
    @ApiOperation(value = "查看单个货品绑定的货品物料清单信息",response = JSONObject.class, notes = "GET查看单个货品绑定的货品物料清单信息")
    public @ResponseBody JSONArray getWmsGoodsBomById(@PathVariable("sshpid") String sshpid) {
        List<WmsGoodsBom> entity=baseService.baseSelectByPrimaryKey(sshpid);
        return JSONArray.fromObject(entity);
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑货品物料清单信息",response = JSONObject.class, notes = "编辑货品物料清单信息")
    public @ResponseBody JSONObject editWmsGoodsBom(@RequestBody List<WmsGoodsBom> list) {
        try{
            baseService.baseUpdateByPrimaryKeySelective(list);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"编辑货品物料清单信息成功","", JSONArray.fromObject(list).toString());
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"编辑货品物料清单信息失败",e.getMessage(),"");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"编辑货品物料清单信息失败",e.getMessage(),"");
        }
    }
}
